package com.weixing.mall.provider.controller.admin;

import com.weixing.mall.base.enums.ResultCodeEnum;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.properties.WeiXingProperties;
import com.weixing.mall.core.properties.ali.OssProperties;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.core.support.upload.AliOssUpload;
import com.weixing.mall.provider.api.model.vo.GoodsPlaceVo;
import com.weixing.mall.provider.model.dto.PhotoAlbumDto;
import com.weixing.mall.provider.model.query.PhotoAlbumQuery;
import com.weixing.mall.provider.model.vo.PhotoAlbumVo;
import com.weixing.mall.provider.service.IPhotoAlbumService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import java.util.UUID;


/**
 * @ClassName PhotoAlbumController
 * @Description TODO <br/>
 * @Author gjq
 * @Modified By:
 * @Date 2019/8/7
 * @Version 1.0
 **/
@RestController
@RequestMapping("photoAlbum")
@Api(value = "相册APi", tags = "相册")
public class PhotoAlbumController extends BaseController {



    @Autowired
    private IPhotoAlbumService photoAlbumService;

    @ApiOperation(value = "分页条件查询相册列表")
    @GetMapping("")
    public Result list(PhotoAlbumQuery photoAlbumQuery){
        return ResultUtil.success(photoAlbumService.selectOfPage(initMpPage(),photoAlbumQuery));
    }

    @ApiOperation(value = "查询相册")
    @GetMapping("getList")
    public Result getList(PhotoAlbumQuery photoAlbumQuery){
        return ResultUtil.success(photoAlbumService.selectList(photoAlbumQuery));
    }

    @ApiOperation(value = "保存相册")
    @PostMapping("save")
    @NoRepeatSubmit
    public Result save(@Validated PhotoAlbumDto photoAlbumDto) {
      /*  PhotoAlbumQuery query=new PhotoAlbumQuery();
        query.setLevel(photoAlbumDto.getAlbumLevel().toString());
        query.setAlbumName(photoAlbumDto.getAlbumName());
        query.setParentId(photoAlbumDto.getParentId());
       List<PhotoAlbumVo> checklist=photoAlbumService.selectList(query);
       if(photoAlbumDto.getId()==null&&checklist.size()>0){
           return ResultUtil.error("该相册名称已经在该层级存在，请重新填写");
       }*/
        photoAlbumService.save(photoAlbumDto);
        return ResultUtil.success();
    }

    /**
     * @Description 批量删除相册，有关联的也删除，删除后图片关联相册的认为默认相册(图片所对应的相册id为0) <br/>
     * @author gjq
     * @date 2019/8/9 14:27
     * @param ids
     * @return com.weixing.mall.base.wrapper.Result
     */
    @ApiOperation(value = "批量删除相册")
    @PostMapping("delAll/{ids}")
    public Result delAll(@PathVariable int[] ids){
        photoAlbumService.delBatch(ids);
        return ResultUtil.success();
    }
    /*
    * flag  为0 根据文件名称，新建目录。为1时，不新建目录
    *
    * */
    @ApiOperation(value = "图片库上传图片 flag  为0 根据文件名称，新建目录。为1时，不新建目录")
    @PostMapping("/importImg")
    public Result upload(@RequestParam("file") MultipartFile file,int flag,Long parentId){
        photoAlbumService.saveImportImg(file,flag,parentId);
        return ResultUtil.success();
    }

    @ApiOperation(value = "关联操作")
    @PostMapping("importExcel")
    public Result importExcel(MultipartFile file) {
       photoAlbumService.improtExcel(file);
        return ResultUtil.success();
    }
    @ApiOperation(value = "关联操作")
    @GetMapping("tree")
    public  Result  tree(){
       List<PhotoAlbumVo> list= photoAlbumService.tree();
       return ResultUtil.success(list);

    }

}
